package com.week2.day03.library;

import java.util.Arrays;
import java.util.Scanner;

public class Menu {
    public static Book[] library = new Book[0];
    public static int num = 0;

    public void menu1() {
        System.out.println("欢迎使用图书管理系统，请输入：");
        boolean flag = true;
        while (flag) {
            System.out.println("1.添加图书\n2.删除图书\n3.修改图书信息\n4.查询图书位置\n5.查看所有图书\n6.退出系统");
            Scanner scanner = new Scanner(System.in);
            int i = scanner.nextInt();
            switch (i) {
                case 1:
                    System.out.println("请输入要添加的书名");
                    String name = scanner.next();
                    System.out.println("请输入存放位置,如A区5号书架2排10列，写作：A_5_2_10");
                    String location = scanner.next();
                    Book book = new Book(name, location);
                    BookManagerImpl bookManagerImpl = new BookManagerImpl();
                    bookManagerImpl.addBook(book);
                    break;
                case 2:
                    System.out.println("请输入要删除的书的id");
                    int id2 = scanner.nextInt();
                    BookManagerImpl bookManagerImpl2 = new BookManagerImpl();
                    bookManagerImpl2.deleteBook(id2);
                    break;
                case 3:
                    System.out.println("请输入要更新的书名");
                    String name3 = scanner.next();
                    System.out.println("请输入新的存放位置,如A区5号书架2排10列，写作：A_5_2_10");
                    String location3 = scanner.next();
                    Book book3 = new Book(name3, location3);
                    BookManagerImpl bookManagerImpl3 = new BookManagerImpl();
                    bookManagerImpl3.modifyBook(book3);
                    break;
                case 4:
                    System.out.println("请输入要查找的书的id");
                    int id4 = scanner.nextInt();
                    BookManagerImpl bookManagerImpl4 = new BookManagerImpl();
                    System.out.println("书名：" + bookManagerImpl4.selectOne(id4).getName() + "\n位置：" + bookManagerImpl4.selectOne(id4).getBookLocation());
                    break;
                case 5:
                    BookManagerImpl bookManagerImpl5 = new BookManagerImpl();
                    System.out.println(Arrays.toString(bookManagerImpl5.selectAll()));
                    break;
                case 6:
                    System.out.println("系统已退出");
                    flag = false;
                    break;
                default:
                    System.out.println("输入有误，请重新输入");
                    break;
            }
        }
    }
}
